<!--
 * @Description: 
 * @Autor: Zhu_liangyu
 * @Date: 2020-05-24 18:13:10
--> 
<template>
  <a-select
    show-search
    allow-clear
    v-model="selectValue"
    placeholder="搜索数据字典"
    style="width: 100%"
    :show-arrow="false"
    :filter-option="false"
    :not-found-content="null"
    @search="fetchUser"
  >
    <a-spin v-if="fetching" slot="notFoundContent" size="small" />
    <a-select-option v-for="d in data" :key="d.codeItemId">{{ d.codeItemName }}</a-select-option>
  </a-select>
</template>
<script>
import { dictionaryTypeList } from "@/api/cms/dictionaryType";
export default {
  model: {
    prop: "value",
    event: "change"
  },
  props: {
    value: {
      type: String
    }
  },
  data() {
    return {
      data: [],
      fetching: false,
      selectValue: this.value
    };
  },
  methods: {
    fetchUser(value) {
      if (value && value != "") {
        var queryparam = { likeAll: value };
        this.fetching = true;
        dictionaryTypeList(queryparam).then(response => {
          this.data = response.data.data;
          this.fetching = false;
        });
      }
    }
  },
  watch: {
    value(val) {
      this.selectValue = val;
    },
    selectValue(val) {
      this.$emit("change", val);
    }
  }
};
</script>
